<%--
  Created by IntelliJ IDEA.
  User: w1057229265
  Date: 2021/6/19
  Time: 19:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.9.15/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.9.15/themes/icon.css">
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.9.15/jquery.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.9.15/jquery.easyui.min.js"></script>
    <script>
        $(function () {
            $('#dg').datagrid({
                url: '/ServletBook?action=getdglist3',
                toolbar: '#tb',
                pagination: true,
                fit: true,
                singleSelect: true,
                columns: [[
                    {field: 'bname', title: '书名称', width: 100},
                    {field: 'bprice', title: '价格', width: 100}
                ]]
            });
            $('#btnAdd1').click(function () {
                if ( $('#dg').datagrid('getSelected') ==null){
                    $.messager.alert('提示','请选择加入购物车','warning')
                    return;
                }
                $('#dd').dialog({
                    title: '加入购物车',
                    width: 300,
                    height: 220,
                    closed: false,
                    cache: false,
                    href: 'bookform.jsp',
                    modal: true,
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            $.messager.progress();	// display the progress bar
                            $('#ff').form('submit', {
                                url: '/ServletCar?action=addcar',
                                onSubmit: function(){
                                    var isValid = $(this).form('validate');
                                    if (!isValid){
                                        $.messager.progress('close');	// hide progress bar while the form is invalid
                                    }
                                    return isValid;	// return false will stop the form submission
                                },
                                success: function(data){
                                    var data = eval('(' + data + ')'); // change the JSON string to javascript object
                                    if (data.code == '200'){
                                        $.messager.alert('提示',data.msg + '请继续购物', 'info')
                                        location.href="book1.jsp"
                                    }
                                    else {
                                        $.messager.alert('提示',data.msg , 'warning')
                                    }
                                    $.messager.progress('close');	// hide progress bar while submit successfully
                                }
                            });
                        }
                    }, {
                        text: '退出',
                        iconCls: 'icon-back',
                        handler: function () {
                            $('#dd').dialog('close');


                        }
                    }]
                });
            });
        })
    </script>

</head>
<body>
<table id="dg">

</table>
<div id="dd"></div>
<div id="tb" style="height:auto">
    <table>
        <tr>
            <td><a id="btnAdd1" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true">加入购物车</a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a id="btnE" href="book11.jsp" class="easyui-linkbutton"
                   data-options="iconCls:'icon-edit',plain:true">详情</a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a id="btnAdd" href="Register.jsp" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true">生成订单</a></td>
            <td>
        </tr>
    </table>
</div>
</body>
</html>
